using System;
using SpecificationPatternCodeV2.Abstracts;
using SpecificationPatternCodeV2.Interfaces;

namespace SpecificationPatternCodeV2.Base
{
	public class RangeSpecification<T> : CompositeSpecification<T> where T : IComparable<T>
	{
		private readonly ISpecification<T> _lower;
		private readonly ISpecification<T> _upper;

		public RangeSpecification(T lower, T upper)
		{
			_lower = new GreaterThanOrEqualToSpecification<T>(lower);
			_upper = new LessThanOrEqualToSpecification<T>(upper);
		}

		public override bool IsSatisfiedBy(T candidate)
		{
			return _lower.And(_upper).IsSatisfiedBy(candidate);
		}
	}
}